Flash MX Professional 2004 Data Integration Using Microsoft Active Server Pages (ASP)
Table of Contents
ASP Sending Results Back to Flash
Near the top of the ASP file, check out the code that creates the Results Packet XML document:
Set ResultsPacket = Server.Createobject("MSXML.DOMDocument")
Set dtd = ResultsPacket.createProcessingInstruction("xml", "version=" & dqt & "1.0" & dqt )
ResultsPacket.appendChild dtd
Set ResultsPacketElement = ResultsPacket.createElement("results_packet")
ResultsPacket.appendChild ResultsPacketElement
To build the results packet, you're simply filling out this XML document, appending one operation node for each insert, update, and delete node in the update packet. Also, as you examine the code in the ASP file, you can see that before you process the update nodes, you issue the following command to set the ID value of the results packet to the ID value of the update packet, so the DataSet in Flash can compare them correctly:
ResultsPacketElement.SetAttribute "transID",UP.getAttribute("transID")
UP is the document root of the update packet. From here on, you can see how to create a results packet operation node for every update packet node processed. Right below the start of the updates loop, you can see this code creating the result packet operation node corresponding to the current update transaction.
Set OpElement = ResultsPacket.createElement("operation")
OpElement.SetAttribute "op","update"
OpElement.SetAttribute "id",UpdateNode.getAttribute("id")
At the end of each node update, you add a msg attribute to the operation node if there was an error, letting the DataSet know that transaction failed. If there is no error, the OpElement node stays just as you made it above, telling Flash that the transaction was successful. You then append that operation node to the results packet, which is the last statement you see in each node type loop:
ResultsPacket.lastChild.appendChild OpElement
The delete and insert loops also create an operation node for each transaction. They work the same way as the updates I have just described.
With the insert loop, you place the value of the autonumber or identity field of the newly created record into a field node under that operation node. This lets the DataSet know what the new id field is for the record it sent. Here is an example of a results packet containing the results of three successful operations:
<results_packet transID="IID72839220893:Fri Jan 23 11:42:15 GMT-0800 2004">
<operation op="update" id="IID4584106663" />
<operation op="delete" id="IID30979323527" />
<operation op="insert" id="IID85040367069">
<field name="contactid" curValue="119" />
</operation>
</results_packet>
At the end of the ASP execution, we have a results packet XML document containing operation nodes that tell the DataSet in Flash how the transactions went with the database. The ASP writes this results packet out with the following line:
Response.Write ResultsPacket.xml